version 14
set more off
set seed 1234

***************************************************************************************************
* THIS ROUTINE GENERATES TABLE III OF WASEEM (2019) RESTAT
***************************************************************************************************

use				"$project_data\ExemptionCutoff_06_11.dta",clear
sort			regnor year
local 			var="seinc"
local			lbound=80000
local			ubound=500000
keep			if employee==0

/* LOG CHANGE IN EARNINGS */

keep 			`var' regnor year industry2 taxableinc
g 				double z0=`var'
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>80000 & z0<=500000
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) & year<2011

/* GENERATING TREATMENT DUMMIES */

g				m_09=(`var'<=300000 & year==2009)
g				m_10=(`var'<=350000 & year==2010)
g				t_09=(`var'>400000 & year==2009)
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}

/* GENERATING TAX RATE VARIABLES */

qui				run "$project_do\taxrate_se.do"
g 				t0=taxrate_se/100 
sort			regnor year
g 				t1=F1.t0
replace			t0=L1.t0 if year==2010		
g 				logchangetrate=log((1-t1)/(1-t0))

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0);
#d				cr

/* DD REGRESSION */

local			i=1
forvalues		z=100000(50000)500000 {
g				z09_`i'=(`var' > (`z'-50000) & `var'<=`z' & year==2009)
g				z10_`i'=(`var' > (`z'-50000) & `var'<=`z' & year==2010)
local			i=`i'+1 
}
forvalues		i=1/7 {
g				treat_09_`i'=(m_09==1 & z09_`i'==1)
g				treat_10_`i'=(m_10==1 & z10_`i'==1)
}
local			i=1
local			j=1
local			e_kw=0.281
local			se_kw=0.159
foreach			z in 80 100 150 200 250 300 {
local			z_0=`z'*1000
local			z_1=`z_0'+50000
if 				`i'==1 {
				local z_1=100000 
}
if				`i'>=5 {
local			e_kw=0.107
local			se_kw=0.039
}
qui				sum z0 if z0>`z_0' & z0<=`z_1' & year==2009 
local			zbar_i=r(mean)
qui				reg logchange i.year treat_09_* treat_10_* t_09, cluster(regnor)
qui				lincom treat_09_`j'+treat_10_`j'
matrix			table[`i',2]=r(estimate)
matrix			table[`i'+1,2]=r(se)
qui				nlcom (exp(_b[treat_09_`j']+_b[treat_10_`j'])-1)*`zbar_i', post
matrix			table[`i',3]=_b[_nl_1]
matrix			table[`i'+1,3]=_se[_nl_1]
qui				sum logchangetrate if z0>`z_0' & z0<=(`z_0'+table[`i',3]) & year==2009 
matrix 			table[`i',4]=r(mean)*`e_kw'*`zbar_i'
matrix			table[`i'+1,4]=r(mean)*`se_kw'*`zbar_i'
matrix 			table[`i',5]=table[`i',3]-table[`i',4]
matrix			table[`i'+1,5]=sqrt((table[`i'+1,3]^2)+(table[`i'+1,4]^2))
matrix 			table[`i',6]=(table[`i',5]/`zbar_i')*100
matrix 			table[`i'+1,6]=(table[`i'+1,5]/`zbar_i')*100
local			i=`i'+2
local			j=`j'+1
}

/* FORMATTING TABLE */

svmat 			table
keep			tab*
keep			if _n<=12
g				c1=""
replace			c1="80-100K" in 1
replace			c1="100-150K" in 3
replace			c1="150-200K" in 5
replace			c1="200-250K" in 7
replace			c1="250-300K" in 9
replace			c1="300-350K" in 11
forvalues 		c=3/5 {
g				c`c'=string(table`c',"%9.0fc")
forvalues		r=2(2)12 {
replace			c`c'="("+string(table`c',"%9.0fc")+")" in `r'
}
}
g				c6=string(table6,"%9.1f")
forvalues		r=2(2)12 {
replace			c6="("+string(table6,"%9.1f")+")" in `r'
}
forvalues		s=1/4 {
g				s`s'="&"
}
g				l="\\"
browse			c1 s1 c3 s2 c4 s3 c5 s4 c6 l


